InvestUtil

object InvestUtil

Miscellaneous investment functions

Properties

Link copied to clipboard
Link copied to clipboard

Marker to identify special sale transactions that are used for unrealized gain calcs.

Functions

Link copied to clipboard

Create a sorted map of date versus buy amount, which includes both cash purchases as well as reinvestments. This map can be used to determine whether a sale transaction represents long term capital gains, short term capital gains, or both.

Link copied to clipboard
fun computeROI(timeSeries: List<ROICashFlowEntry>?, seedPercent: Double): Double

Compute Internal Rate of Return (IRR) - sometimes referred to as the Return On Investment (ROI), or Annual Return Percent. Critically the IRR is an expression of the return over time (i.e. annualised), whereas a simple ROI does take time into account. Defaults to the Secant problem solving strategy, with: max 100 iterations, and no seed sign reversal upon problem resolution failure. There can be more than one solution to solving IRR - there is no guaranteed which solution will be presented. This largely depends on the starting seed (initial guess) Refer: IRR.computeIRR for more details

Link copied to clipboard

Generate a sale transaction as if all remaining shares of a security were sold off as of a specific date. This method should be used for securities using lot-based cost tracking.

fun generateUnrealizedSaleTxn(secAcct: Account, shares: Long, asofDate: Int): SplitTxn

Generate a sale transaction as if all remaining shares of a security were sold off as of a specific date. This method should be used for securities using the average cost method.

Link copied to clipboard
fun getBuyTracker(sec: Account?, secCurr: CurrencyType, investCurr: CurrencyType, split: SplitTxn): CapitalGainBuy?

Generate a tracking class for a buy transaction when using average cost method. This tracker is used to figure out which shares are sold first (FIFO) so that long term and short term capital gains can be computed.

Link copied to clipboard

Returns the current cost basis for the given security. (based on 'balance' which could be future-dated). MD2024(5100) calls the unified CostCalculation class for both average and lot controlled... ... unified method and applies to both average cost and lot controlled securities.

fun getCostBasis(sec: Account, asOfDateInt: Int): Long

Returns the cost basis for the given security, for the given asof date. Unified method and applies to both average cost and lot controlled securities. Added February 2024 by Stuart Beesley using the new CostCalculation class since MD2024(5100).

Link copied to clipboard

Returns a CapitalGainResult class/calculation for the given sell transaction for the given security. Works for both Average and LOT controlled securities. Updated February 2024 by Stuart Beesley to use new CostCalculation class since MD2024(5100).

Link copied to clipboard

Returns a list of CapitalGainResult class/calculations for all sell transactions for the given security within the date range. Works for both Average and LOT controlled securities. The asof date is assumed to be today/future. There will be one CapitalGainResult entry per sell txn. Added February 2024 by Stuart Beesley using the new CostCalculation class since MD2024(5100).

Returns a list of CapitalGainResult class/calculations for all sell transactions for the given security within the date range. Works for both Average and LOT controlled securities. Values will be calculated as of the given asOfDateInt. There will be one CapitalGainResult entry per sell txn. Added February 2024 by Stuart Beesley using the new CostCalculation class since MD2024(5100).

Link copied to clipboard

Returns a single (complete) CapitalGainResult class/calculation total for all sell transactions for the given security within the given date range. Works for both Average and LOT controlled securities. The asof date is assumed to be today/future. Added February 2024 by Stuart Beesley using the new CostCalculation class since MD2024(5100).

Returns a single (complete) CapitalGainResult class/calculation total for all sell transactions for the given security within the given date range. Works for both Average and LOT controlled securities. Values will be calculated as of the given asOfDateInt. Added February 2024 by Stuart Beesley using the new CostCalculation class since MD2024(5100).

Link copied to clipboard
fun getCostCalculation(sec: Account, asOfDateInt: Int? = null, preparedTxns: TxnSet? = null, obtainCurrentBalanceToo: Boolean = false, unRealizedSaleTxn: SplitTxn? = null): CostCalculation

Returns a CostCalculation class for the given security account and given parameters. Added February 2024 by Stuart Beesley using the new CostCalculation class since MD2024(5100).

Link copied to clipboard

Compute the cost per share, avoiding a divide by zero fault (returns zero if no shares).

Link copied to clipboard

Compute the net sale amount, in the currency of the parent investment account, of a sale transaction. Returns zero if not a sale transaction. Returns the cash proceeds of the sale less any transaction fees or commission.

Link copied to clipboard

Determine the remaining lots in a lot-based security account, as of a specified date, accounting for all sales on or prior to that date.

Link copied to clipboard
fun getSecurityBalanceInfo(secAccount: Account, shares: Long, asofDate: Int, baseCurrency: CurrencyType?, decimal: Char): String

Get security balance detailed info on the shares and price per share.

Link copied to clipboard

Quickly determine if the cost basis for a Security Account is valid. Only applies to lot controlled securities. Average cost always returns true.

Link copied to clipboard

Determine if a transaction is an income from the fund or if it is a 'bank' transaction where the user is putting money in or taking money out.

Link copied to clipboard

Determine if a transaction is a transaction that can be considered a sale, which is treated specially for capital gains.

Link copied to clipboard

Determine if a transaction is a 'bank' transaction where the user is putting money in or taking money out. For the purposes of this test, we need to know whether some bank account in the list of accounts will change in cash value. This includes the investment account cash value and any external accounts via transfers.

Link copied to clipboard
fun processLotBasedTxn(acctTxns: TxnSet?, split: SplitTxn, secCurr: CurrencyType?, unrealizedAsOfDate: Int, result: Hashtable<String, AvailableSharesTracker>)

Process a transaction for a security that uses lot-based cost. For buys, the shares bought are added to the resulting available shares. For sales, the shares sold are removed from the respective lots, as they are no longer available. If a split had occurred, the available shares are adjusted accordingly.

Link copied to clipboard
fun recomputeStartDate(timeSeries: List<ROICashFlowEntry>?, currentBeginDate: Int): Int

Recomputes the start date for a list of cash flows. The start date affects the result of an IRR computation the most, since every cash flow is computed against the start date. There are times when you should recompute the start date because it has been initially estimated, for example when the user picks 'All Dates' in a report and the start date defaults to 1970. This (for example) would make the IRR computation artificially low. Note: This function mutates the entries in cashFlows (i.e. start date and annums in period). Clone them first if shared elsewhere. Refer: IRR.recomputeStartDate for more details